﻿Imports Microsoft.VisualBasic
Imports ADOEntity
Imports ADOEntityKYC
Imports ADOEntityAMLO101
Imports ADOEntityAMLO102
Imports ADOEntityAMLO103
Imports System.Data
Imports ADOEntityAMLO1059
Imports DevExpress.Web.ASPxEditors


Public Class clsMasterDropDown

    Public Enum BranchType
        TypeBranch = 1
        TypePart = 2
        TypeAdmin = 3
    End Enum
    Dim clsDB As New clsDatabase

    Dim sBranch As IList(Of ADOEntity.SBRANCH) = Nothing
    Dim sDepartment As IList(Of ADOEntity.SDEPARTMENT) = Nothing

    '--------- ADMIN ----------
#Region " Department"

    Public Sub setDeptToDdlSearch(ByRef ddlData As DropDownList, _
                                  Optional ByVal selectData As String = "", _
                                  Optional ByVal strDeptCode As String = "", _
                                  Optional ByVal strRoleCode As String = "0")
        Try
            Dim userEntity As UserEntities = New UserEntities
            Dim AddItem As ListItem = Nothing
            Dim qrySdepartment = (From sDepartment In userEntity.SDEPARTMENT _
                                  Order By sDepartment.DEPTCODE Ascending _
                                  Select sDepartment.DEPTCODE, _
                                  DEPTNAME = sDepartment.DEPTCODE & " : " & sDepartment.DEPTNAME).ToList

            If (strRoleCode > 79) Then
                AddItem = New ListItem(Resources.resClsMasterDropdown.Select_Search, 0)
            ElseIf (strRoleCode > 0 And strRoleCode < 80) Then
                qrySdepartment = qrySdepartment.Where(Function(fn) Convert.ToInt32(fn.DEPTCODE) = strDeptCode).ToList
            Else

            End If

            ddlData.DataSource = qrySdepartment
            ddlData.DataTextField = "DEPTNAME"
            ddlData.DataValueField = "DEPTCODE"
            ddlData.DataBind()

            If Not (AddItem Is Nothing) Then
                ddlData.Items.Insert(0, AddItem)
            End If

            If Not (selectData = "") Then
                ddlData.SelectedValue = selectData
            End If

            qrySdepartment = Nothing
            userEntity.Dispose()
            userEntity = Nothing
        Catch ex As Exception
            Throw ex
        End Try


    End Sub

    Public Sub setDeptToDdl(ByRef ddlData As DropDownList, _
                                  Optional ByVal selectData As String = "", _
                                  Optional ByVal strDeptCode As String = "", _
                                  Optional ByVal strRoleCode As String = "0")

        Dim userEntity As UserEntities = New UserEntities
        Dim AddItem As ListItem = Nothing
        Dim qrySdepartment = (From sDepartment In userEntity.SDEPARTMENT Order By sDepartment.DEPTCODE Ascending Select sDepartment.DEPTCODE, _
                              DEPTNAME = sDepartment.DEPTCODE & " : " & sDepartment.DEPTNAME).ToList

        If (strRoleCode > 79) Then
            AddItem = New ListItem(Resources.resClsMasterDropdown.SelectDepartment_Manage, 0)
        ElseIf (strRoleCode > 0 And strRoleCode < 80) Then
            qrySdepartment = qrySdepartment.Where(Function(fn) fn.DEPTCODE = strDeptCode).ToList
        End If

        ddlData.DataSource = qrySdepartment
        ddlData.DataTextField = "DEPTNAME"
        ddlData.DataValueField = "DEPTCODE"
        ddlData.DataBind()

        If Not (AddItem Is Nothing) Then
            ddlData.Items.Insert(0, AddItem)
        End If

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qrySdepartment = Nothing
        userEntity.Dispose()
        userEntity = Nothing

    End Sub


#End Region

#Region " Branch "

    Public Sub setBranchToDdl(ByRef ddlData As DropDownList, _
                                Optional ByVal strRoleCode As String = "0", _
                                Optional ByVal strDeptCode As String = "", _
                                Optional ByVal strZoneCode As String = "", _
                                Optional ByVal strBranchCode As String = "", _
                                Optional ByVal selectData As String = "")
        Dim userEntity As UserEntities = New UserEntities
        Dim AddItem As ListItem = Nothing

        Dim qrySbranch = From sBranch In userEntity.SBRANCH Order By sBranch.DEPTCODE, sBranch.BRANCHCODE Ascending

        If (strRoleCode > 79) Then
            qrySbranch = qrySbranch.Where(Function(fn) fn.DEPTCODE = strDeptCode)
            AddItem = New ListItem(Resources.resClsMasterDropdown.Select_Search, 0)
        ElseIf (strRoleCode > 69 And strRoleCode < 80) Then
            qrySbranch = qrySbranch.Where(Function(fn) fn.DEPTCODE = strDeptCode)
        ElseIf (strRoleCode > 59 And strRoleCode < 70) Then
            qrySbranch = qrySbranch.Where(Function(fn) fn.DEPTCODE = strDeptCode And fn.ZONECODE = strZoneCode)
        ElseIf (strRoleCode > 0 And strRoleCode < 60) Then
            qrySbranch = qrySbranch.Where(Function(fn) fn.BRANCHCODE = strBranchCode)
        End If



        ddlData.DataSource = qrySbranch.ToList
        ddlData.DataTextField = "BRANCHNAME"
        ddlData.DataValueField = "BRANCHCODE"
        ddlData.DataBind()

        If Not (AddItem Is Nothing) Then
            ddlData.Items.Insert(0, AddItem)
        End If
        qrySbranch = Nothing
        userEntity.Dispose()
        userEntity = Nothing

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

    End Sub

    'Public Sub setBranchUseAllCodeToDdl(ByRef ddlData As DropDownList, _
    '                            Optional ByVal strRoleCode As String = "0", _
    '                            Optional ByVal strDeptCode As String = "", _
    '                            Optional ByVal strZoneCode As String = "", _
    '                            Optional ByVal strBranchCode As String = "", _
    '                            Optional ByVal selectData As String = "")
    '    Dim userEntity As userEntities = New userEntities
    '    Dim AddItem As ListItem = Nothing

    '    Dim qrySbranch = From sBranch In userEntity.SBRANCH Order By sBranch.DEPTCODE, sBranch.BRANCHCODE Ascending Select sBranch.BRANCHCODE, sBranch.ALLCODERIGHT, sBranch.DEPTCODE, sBranch.ZONECODE, BRANCHNAME = sBranch.BRANCHCODE & " : " & sBranch.BRANCHNAME
    '    AddItem = New ListItem(Resources.resClsMasterDropdown.SelectBranch_Manage, 0)
    '    If (strRoleCode > 79) Then
    '        qrySbranch = qrySbranch.Where(Function(fn) fn.DEPTCODE = strDeptCode)
    '    ElseIf (strRoleCode > 69) Then
    '        qrySbranch = qrySbranch.Where(Function(fn) fn.DEPTCODE = strDeptCode)
    '    ElseIf (strRoleCode > 59) Then
    '        qrySbranch = qrySbranch.Where(Function(fn) fn.DEPTCODE = strDeptCode And fn.ZONECODE = strZoneCode)
    '    ElseIf (strRoleCode > 0 And strRoleCode < 60) Then
    '        qrySbranch = qrySbranch.Where(Function(fn) fn.BRANCHCODE = strBranchCode)
    '    End If


    '    ddlData.DataSource = qrySbranch.ToList
    '    ddlData.DataTextField = "BRANCHNAME"
    '    ddlData.DataValueField = "ALLCODERIGHT"
    '    ddlData.DataBind()
    '    If Not (AddItem Is Nothing) Then
    '        ddlData.Items.Insert(0, AddItem)
    '    End If

    '    qrySbranch = Nothing
    '    userEntity.Dispose()
    '    userEntity = Nothing

    '    If Not (selectData = "") Then
    '        ddlData.SelectedValue = selectData
    '    End If

    'End Sub

    Public Sub setBranchUseAllCodeToDdl(ByRef ddlData As DropDownList, _
                                        Optional ByVal zoneCodeUse As String = "", _
                                        Optional ByVal strRoleCode As String = "0", _
                                        Optional ByVal strDeptCode As String = "", _
                                        Optional ByVal strZoneCode As String = "", _
                                        Optional ByVal strBranchCode As String = "", _
                                        Optional ByVal selectData As String = "")
        Dim userEntity As UserEntities = New UserEntities
        Dim AddItem As ListItem = Nothing

        Dim qrySbranch = From sBranch In userEntity.SBRANCH Order By sBranch.DEPTCODE, sBranch.BRANCHCODE Ascending
                         Select sBranch.BRANCHCODE, sBranch.ALLCODERIGHT, sBranch.DEPTCODE,
                         sBranch.ZONECODE, BRANCHNAME = sBranch.BRANCHCODE & " : " & sBranch.BRANCHNAME

        AddItem = New ListItem(Resources.resClsMasterDropdown.SelectBranch_Manage, 0)
        If (strRoleCode > 79) Then
            '  qrySbranch = qrySbranch.Where(Function(fn) fn.DEPTCODE = strDeptCode)
        ElseIf (strRoleCode > 69) Then
            qrySbranch = qrySbranch.Where(Function(fn) fn.DEPTCODE = strDeptCode)
        ElseIf (strRoleCode > 59) Then
            qrySbranch = qrySbranch.Where(Function(fn) fn.DEPTCODE = strDeptCode And fn.ZONECODE = strZoneCode)
        ElseIf (strRoleCode > 0 And strRoleCode < 60) Then
            qrySbranch = qrySbranch.Where(Function(fn) fn.BRANCHCODE = strBranchCode)
        End If

        If Not (strDeptCode = "") Then
            qrySbranch = qrySbranch.Where(Function(fn) fn.DEPTCODE = strDeptCode)
        End If

        If Not (zoneCodeUse = "") Then
            qrySbranch = qrySbranch.Where(Function(fn) fn.ZONECODE = zoneCodeUse)
        End If


        ddlData.DataSource = qrySbranch.ToList
        ddlData.DataTextField = "BRANCHNAME"
        ddlData.DataValueField = "ALLCODERIGHT"
        ddlData.DataBind()
        If Not (AddItem Is Nothing) Then
            ddlData.Items.Insert(0, AddItem)
        End If

        qrySbranch = Nothing
        userEntity.Dispose()
        userEntity = Nothing

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

    End Sub

    Public Sub setBranchDdlSearch(ByRef ddlData As DropDownList, _
                                Optional ByVal strRoleCode As String = "0", _
                                Optional ByVal strDeptCode As String = "", _
                                Optional ByVal strZoneCode As String = "", _
                                Optional ByVal strBranchCode As String = "", _
                                Optional ByVal selectData As String = "")


        Dim userEntity As UserEntities = New UserEntities
        Dim AddItem As ListItem = Nothing

        Dim qrySbranch = From sBranch In userEntity.SBRANCH Order By sBranch.DEPTCODE, sBranch.BRANCHCODE Ascending
                         Select sBranch.BRANCHCODE, BRANCHNAME = sBranch.BRANCHCODE & " : " & sBranch.BRANCHNAME, sBranch.DEPTCODE, sBranch.ZONECODE

        AddItem = New ListItem(Resources.resClsMasterDropdown.Select_Search, 0)
        If (strRoleCode > 79) Then
            If Not (strDeptCode = "0") Then
                qrySbranch = qrySbranch.Where(Function(fn) fn.DEPTCODE = strDeptCode)
            End If
        ElseIf (strRoleCode > 69) Then
            qrySbranch = qrySbranch.Where(Function(fn) fn.DEPTCODE = strDeptCode)
        ElseIf (strRoleCode > 59) Then
            qrySbranch = qrySbranch.Where(Function(fn) fn.DEPTCODE = strDeptCode And fn.ZONECODE = strZoneCode)
        ElseIf (strRoleCode > 0 And strRoleCode < 60) Then
            qrySbranch = qrySbranch.Where(Function(fn) fn.BRANCHCODE = strBranchCode)
        End If


        ddlData.DataSource = qrySbranch.ToList
        ddlData.DataTextField = "BRANCHNAME"
        ddlData.DataValueField = "BRANCHCODE"
        ddlData.DataBind()

        If Not (AddItem Is Nothing) Then
            If Not (strRoleCode > 0 And strRoleCode < 60) Then
                ddlData.Items.Insert(0, AddItem)
            End If
        End If

        qrySbranch = Nothing
        userEntity.Dispose()
        userEntity = Nothing

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

    End Sub


#End Region

#Region " Program "

    Public Sub setProgramToDdl(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim userEntity As UserEntities = New UserEntities
        Dim qrySProgram = (From sProgram In userEntity.SPROGRAM Order By sProgram.PROGRAMCODE Ascending).ToList
        Dim AddItem As New ListItem(Resources.resClsMasterDropdown.SelectProgram_Manage, 0)
        ddlData.DataSource = qrySProgram
        ddlData.DataTextField = "PROGRAMNAME"
        ddlData.DataValueField = "PROGRAMCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        qrySProgram = Nothing
        userEntity.Dispose()
        userEntity = Nothing

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If
    End Sub

#End Region

#Region " UserRight "

    Public Sub setUserRightToDd(ByRef ddlData As DropDownList,
                                Optional ByVal strRoleCode As String = "0", _
                                Optional ByVal selectData As String = "", _
                                Optional ByVal strDepCode As String = "0")
        Dim userEntity As UserEntities = New UserEntities

        Dim AddItem As ListItem = New ListItem(Resources.resClsMasterDropdown.SelectUserRight_Manage, 0)

        Dim qrySserRight = From tblUserRight In userEntity.SUSERRIGHT Group Join tblRefDept In userEntity.USERRIGHTDEPT _
                           On tblUserRight.USERRIGHT Equals tblRefDept.USERRIGHT Into tblLeft = Group _
                           From tblJoin In tblLeft.DefaultIfEmpty
                           Order By tblUserRight.USERRIGHT Ascending
                           Select tblUserRight.USERRIGHT, tblUserRight.USERRIGHTDESC, tblUserRight.ROLEGHB, _
                                    tblUserRight.ROLESYS, tblUserRight.ROLEDEPT, tblUserRight.ROLEZONE, _
                                    tblUserRight.ROLEBRANCH, tblUserRight.ROLEUSER, tblJoin.DEPTCODE

        If (strRoleCode > 89) Then
        ElseIf (strRoleCode > 79) Then
        ElseIf (strRoleCode > 69) Then
            qrySserRight = qrySserRight.Where(Function(fn) fn.ROLEDEPT = 1 Or fn.ROLEZONE = 1 Or fn.ROLEBRANCH = 1 Or fn.ROLEUSER = 1)
        ElseIf (strRoleCode > 59) Then
            qrySserRight = qrySserRight.Where(Function(fn) fn.ROLEZONE = 1 Or fn.ROLEBRANCH = 1 Or fn.ROLEUSER = 1)
        ElseIf (strRoleCode > 49) Then
            qrySserRight = qrySserRight.Where(Function(fn) fn.ROLEBRANCH = 1 Or fn.ROLEUSER = 1)
        ElseIf (strRoleCode < 50) Then
            qrySserRight = qrySserRight.Where(Function(fn) fn.ROLEUSER = 1)
        End If

        If Not (strDepCode = "0") Then
            qrySserRight = qrySserRight.Where(Function(fn) fn.DEPTCODE = strDepCode)
        End If


        If Not (strRoleCode = "0") Then
            If (strRoleCode > 89) Then
                qrySserRight = qrySserRight.Where(Function(fn) fn.ROLEGHB = 1)
            ElseIf (strRoleCode > 79) Then
                qrySserRight = qrySserRight.Where(Function(fn) fn.ROLESYS = 1)
            ElseIf (strRoleCode > 69) Then
                qrySserRight = qrySserRight.Where(Function(fn) fn.ROLEDEPT = 1)
            ElseIf (strRoleCode > 59) Then
                qrySserRight = qrySserRight.Where(Function(fn) fn.ROLEZONE = 1)
            ElseIf (strRoleCode > 49) Then
                qrySserRight = qrySserRight.Where(Function(fn) fn.ROLEBRANCH = 1)
            ElseIf (strRoleCode < 50) Then
                qrySserRight = qrySserRight.Where(Function(fn) fn.ROLEUSER = 1)
            End If
        End If

        Dim qryDistinct = From tbl In qrySserRight Select tbl.USERRIGHT, tbl.USERRIGHTDESC
        ddlData.DataSource = qryDistinct.Distinct.OrderBy(Function(fn) fn.USERRIGHT).ToList
        ddlData.DataTextField = "UserRightDesc"
        ddlData.DataValueField = "UserRight"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        qrySserRight = Nothing
        userEntity.Dispose()
        userEntity = Nothing

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If
    End Sub

    Public Sub setUserRightToDdl(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim userEntity As UserEntities = New UserEntities
        Dim qrySserRight = (From tblUserRight In userEntity.SUSERRIGHT Order By tblUserRight.USERRIGHT Ascending).ToList
        Dim AddItem As New ListItem(Resources.resClsMasterDropdown.SelectUserRight_Manage, 0)
        ddlData.DataSource = qrySserRight
        ddlData.DataTextField = "UserRightDesc"
        ddlData.DataValueField = "UserRight"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        qrySserRight = Nothing
        userEntity.Dispose()
        userEntity = Nothing

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If
    End Sub

    Public Sub setUserRightToDdlSearch(ByRef ddlData As DropDownList,
                                Optional ByVal strRoleCode As String = "0", _
                                Optional ByVal selectData As String = "", _
                                Optional ByVal strDepCode As String = "0")
        Dim userEntity As UserEntities = New UserEntities

        Dim qrySserRight = From tblUserRight In userEntity.SUSERRIGHT Group Join tblRefDept In userEntity.USERRIGHTDEPT _
                          On tblUserRight.USERRIGHT Equals tblRefDept.USERRIGHT Into tblLeft = Group _
                          From tblJoin In tblLeft.DefaultIfEmpty
                          Order By tblUserRight.USERRIGHT Ascending
                          Select tblUserRight.USERRIGHT, tblUserRight.USERRIGHTDESC, tblUserRight.ROLEGHB, _
                                   tblUserRight.ROLESYS, tblUserRight.ROLEDEPT, tblUserRight.ROLEZONE, _
                                   tblUserRight.ROLEBRANCH, tblUserRight.ROLEUSER, tblJoin.DEPTCODE

        If (strRoleCode > 89) Then
        ElseIf (strRoleCode > 79) Then
        ElseIf (strRoleCode > 69) Then
            qrySserRight = qrySserRight.Where(Function(fn) fn.ROLEDEPT = 1 Or fn.ROLEZONE = 1 Or fn.ROLEBRANCH = 1 Or fn.ROLEUSER = 1)
        ElseIf (strRoleCode > 59) Then
            qrySserRight = qrySserRight.Where(Function(fn) fn.ROLEZONE = 1 Or fn.ROLEBRANCH = 1 Or fn.ROLEUSER = 1)
        ElseIf (strRoleCode > 49) Then
            qrySserRight = qrySserRight.Where(Function(fn) fn.ROLEBRANCH = 1 Or fn.ROLEUSER = 1)
        ElseIf (strRoleCode < 50) Then
            qrySserRight = qrySserRight.Where(Function(fn) fn.ROLEUSER = 1)
        End If

        If Not (strDepCode = "0") Then
            qrySserRight = qrySserRight.Where(Function(fn) fn.DEPTCODE = strDepCode)
        End If

        Dim qryDistinct = From tbl In qrySserRight Select tbl.USERRIGHT, tbl.USERRIGHTDESC

        Dim AddItem As New ListItem(Resources.resClsMasterDropdown.Select_Search, 0)
        ddlData.DataSource = qryDistinct.Distinct.OrderBy(Function(fn) fn.USERRIGHT).ToList
        ddlData.DataTextField = "UserRightDesc"
        ddlData.DataValueField = "UserRight"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        qrySserRight = Nothing
        userEntity.Dispose()
        userEntity = Nothing

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If
    End Sub
#End Region

#Region " Role "

    Public Sub setRoleToDdl(ByRef ddlData As DropDownList, _
                            Optional ByVal selectData As String = "", _
                            Optional ByVal strRoleCode As String = "0", _
                            Optional ByVal strWhere As String = "")
        Dim userEntity As UserEntities = New UserEntities
        Dim AddItem As ListItem = Nothing

        Dim qryRole = (From tblRole In userEntity.SROLE Order By tblRole.ROLECODE Ascending).ToList

        AddItem = New ListItem(Resources.resClsMasterDropdown.SelectUserRole_Manage, 0)
        If (strRoleCode > 79) Then
            qryRole = qryRole.Where(Function(fn) Convert.ToInt32(fn.ROLECODE) < strRoleCode).ToList
        ElseIf (strRoleCode > 69 And strRoleCode < 80) Then
            qryRole = qryRole.Where(Function(fn) Convert.ToInt32(fn.ROLECODE) < strRoleCode).ToList
        ElseIf (strRoleCode > 59 And strRoleCode < 70) Then
            qryRole = qryRole.Where(Function(fn) Convert.ToInt32(fn.ROLECODE) < strRoleCode).ToList
        ElseIf (strRoleCode > 49 And strRoleCode < 60) Then
            qryRole = qryRole.Where(Function(fn) Convert.ToInt32(fn.ROLECODE) < strRoleCode).ToList
        ElseIf strRoleCode < 50 Then
            qryRole = qryRole.Where(Function(fn) Convert.ToInt32(fn.ROLECODE) < 50).ToList
        End If

        If (strWhere = "ZZZ" Or strWhere = "") Then
            qryRole = qryRole.Where(Function(fn) Convert.ToInt32(fn.ROLECODE) <> 60).ToList
        End If

        ddlData.DataSource = qryRole
        ddlData.DataTextField = "ROLENAME"
        ddlData.DataValueField = "ROLECODE"
        ddlData.DataBind()

        If Not (AddItem Is Nothing) Then
            ddlData.Items.Insert(0, AddItem)
        End If

        qryRole = Nothing
        userEntity.Dispose()
        userEntity = Nothing

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If
    End Sub


    Public Sub setRoleToDdlSearch(ByRef ddlData As DropDownList, _
                                  Optional ByVal selectData As String = "", _
                                  Optional ByVal strCondition As String = "", _
                                  Optional ByVal strRoleCode As String = "0")
        Dim userEntity As UserEntities = New UserEntities
        Dim AddItem As ListItem = Nothing
        Dim qryRole = (From tblRole In userEntity.SROLE Order By tblRole.ROLECODE Ascending).ToList

        'If (strRoleCode > 79) Then
        '    AddItem = New ListItem(Resources.resClsMasterDropdown.Select_Search, 0)
        '    qryRole = qryRole.Where(Function(fn) Convert.ToInt32(fn.ROLECODE) > 79).ToList
        'ElseIf (strRoleCode > 69 And strRoleCode < 80) Then
        '    qryRole = qryRole.Where(Function(fn) Convert.ToInt32(fn.ROLECODE) > 69 And Convert.ToInt32(fn.ROLECODE) < 80).ToList
        'ElseIf (strRoleCode > 59 And strRoleCode < 70) Then
        '    qryRole = qryRole.Where(Function(fn) Convert.ToInt32(fn.ROLECODE) > 59 And Convert.ToInt32(fn.ROLECODE) < 70).ToList
        'ElseIf (strRoleCode > 49 And strRoleCode < 60) Then
        '    qryRole = qryRole.Where(Function(fn) Convert.ToInt32(fn.ROLECODE) > 49 And Convert.ToInt32(fn.ROLECODE) < 60).ToList
        'Else
        '    qryRole = qryRole.Where(Function(fn) Convert.ToInt32(fn.ROLECODE) < 50).ToList
        'End If
        If (strRoleCode > 79) Then
            AddItem = New ListItem(Resources.resClsMasterDropdown.SelectUserRight_Manage, 0)
            qryRole = qryRole.Where(Function(fn) Convert.ToInt32(fn.ROLECODE) < strRoleCode).ToList
        ElseIf (strRoleCode > 69 And strRoleCode < 80) Then
            qryRole = qryRole.Where(Function(fn) Convert.ToInt32(fn.ROLECODE) < strRoleCode).ToList
        ElseIf (strRoleCode > 59 And strRoleCode < 70) Then
            qryRole = qryRole.Where(Function(fn) Convert.ToInt32(fn.ROLECODE) < strRoleCode).ToList
        ElseIf (strRoleCode > 49 And strRoleCode < 60) Then
            qryRole = qryRole.Where(Function(fn) Convert.ToInt32(fn.ROLECODE) < strRoleCode).ToList
        Else
            qryRole = qryRole.Where(Function(fn) Convert.ToInt32(fn.ROLECODE) < 50).ToList
        End If

        ddlData.DataSource = qryRole
        ddlData.DataTextField = "ROLENAME"
        ddlData.DataValueField = "ROLECODE"
        ddlData.DataBind()

        If Not (AddItem Is Nothing) Then
            ddlData.Items.Insert(0, AddItem)
        End If

        qryRole = Nothing
        userEntity.Dispose()
        userEntity = Nothing

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If
    End Sub

#End Region

#Region " Zone"

    Public Sub setZoneToDdl(ByRef ddlData As DropDownList, _
                            Optional ByVal selectData As String = "", _
                            Optional ByVal strZoneCode As String = "", _
                            Optional ByVal strRoleCode As String = "0",
                            Optional ByVal strDeptCode As String = "0")
        Dim userEntity As UserEntities = New UserEntities

        Dim qrySZone = (From sZone In userEntity.SZONE _
                        Order By sZone.ZONEINDEX Ascending, sZone.ZONECODE _
                        Select sZone.ZONECODE, ZONENAME = If(sZone.ZONENAME = "-", "-", sZone.ZONECODE & " : " & sZone.ZONENAME), sZone.ZONEINDEX, sZone.DEPTCODE).ToList

        If (strRoleCode < 70) Then
            qrySZone = qrySZone.Where(Function(fn) fn.ZONECODE = strZoneCode).ToList
        End If

        If Not (strDeptCode = "0") Then
            qrySZone = qrySZone.Where(Function(fn) fn.DEPTCODE = strDeptCode Or fn.DEPTCODE = "").ToList
        End If

        ddlData.DataSource = qrySZone
        ddlData.DataTextField = "ZONENAME"
        ddlData.DataValueField = "ZONECODE"

        ddlData.DataBind()

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        Else
            ddlData.SelectedValue = "ZZZ"
        End If

        qrySZone = Nothing
        userEntity.Dispose()
        userEntity = Nothing
    End Sub

    Public Sub setZoneToDdlSearch(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim userEntity As UserEntities = New UserEntities
        Dim qrySZone = Nothing
        qrySZone = (From sZone In userEntity.SZONE Order By sZone.ZONEINDEX Ascending).ToList



        Dim AddItem As New ListItem(Resources.resClsMasterDropdown.Select_Search, -1)

        ddlData.DataSource = qrySZone
        ddlData.DataTextField = "ZONENAME"
        ddlData.DataValueField = "ZONECODE"

        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        Else

            ddlData.SelectedValue = "ZZZ"
        End If

        qrySZone = Nothing
        userEntity.Dispose()
        userEntity = Nothing
    End Sub





#End Region

#Region "Sanction List"
    Sub setSource(ByRef ddlData As DropDownList)
        Dim AddItem As ListItem = Nothing
        Dim fnDateFormat As New clsDateFormat
        AddItem = New ListItem(Resources.resClsMasterDropdown.Select_Search, 0)

        Dim sanctionEntity As SanctionEntities = New SanctionEntities
        ' Dim qryS = From S In sanctionEntity.AMLLIST_HIST Order By S.DATASOURCE Select S.DATASOURCE, Source = S.DATASOURCE
        Dim qryS = From S In sanctionEntity.MSANCTIONLIST Order By S.LISTTYPECODE Select S.LISTTYPECODE, S.LISTTYPENAME

        ', Source = S.DATASOURCE

        ddlData.DataSource = qryS.ToList
        ddlData.DataTextField = "LISTTYPECODE"
        ddlData.DataValueField = "LISTTYPECODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        qryS = Nothing

        sanctionEntity.Dispose()
        sanctionEntity = Nothing

    End Sub
    Sub setLastUpdateDate(ByRef ddlData As DropDownList, Optional ByVal DataSourceValue As String = "")

        ddlData.Items.Clear()

        Dim AddItem As ListItem = Nothing
        Dim fnDateFormat As New clsDateFormat
        AddItem = New ListItem(Resources.resClsMasterDropdown.Select_Search, 0)

        Dim sanctionEntity As SanctionEntities = New SanctionEntities
        Dim qryS1 = From S1 In sanctionEntity.AMLLIST_HIST
                    Order By S1.LASTUPDATEDATE Descending
                    Select S1.LASTUPDATEDATE, S1.DATASOURCE, BATCH = S1.LASTUPDATEDATE

        If Not (DataSourceValue = "") Then
            qryS1 = qryS1.Where(Function(fn) fn.DATASOURCE = DataSourceValue)
        End If

        ddlData.DataSource = qryS1.Distinct.OrderByDescending(Function(fn) fn.LASTUPDATEDATE).ToList
        ddlData.DataTextField = "LASTUPDATEDATE"
        ddlData.DataValueField = "LASTUPDATEDATE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)
        qryS1 = Nothing
    End Sub
#End Region




    '--------------AMLO--------------------
    Dim Amlo101_Entity As AMLO101Entities = Nothing


#Region " AMLO101"

#Region " Master "
    Public Sub setBranchToDdl_AMLO101(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO101Entities, _
                                          Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo101_Entity = objAmloEntity
        Dim qrySbranch = Nothing
        If (strCondition = "") Then
            qrySbranch = (From sBranch In Amlo101_Entity.SBRANCH Order By sBranch.DEPTCODE, sBranch.BRANCHCODE Ascending).ToList
        Else
            qrySbranch = (From sBranch In Amlo101_Entity.SBRANCH Where sBranch.DEPTCODE = strCondition Order By sBranch.DEPTCODE, sBranch.BRANCHCODE Ascending).ToList
        End If

        Dim AddItem As New ListItem(Resources.resUser.SelectBranch, 0)
        ddlData.DataSource = qrySbranch
        ddlData.DataTextField = "BRANCHNAME"
        ddlData.DataValueField = "BRANCHCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qrySbranch = Nothing


    End Sub
    Public Sub setBranchToDdl_AMLO101Search(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO101Entities, _
                                      Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo101_Entity = objAmloEntity
        Dim qrySbranch = Nothing
        If (strCondition = "") Then
            qrySbranch = (From sBranch In Amlo101_Entity.SBRANCH Order By sBranch.DEPTCODE, sBranch.BRANCHCODE Ascending).ToList
        Else
            qrySbranch = (From sBranch In Amlo101_Entity.SBRANCH Where sBranch.DEPTCODE = strCondition Order By sBranch.DEPTCODE, sBranch.BRANCHCODE Ascending).ToList

        End If

        Dim AddItem As New ListItem(Resources.resUser.SelectBranchSearch, 0)
        ddlData.DataSource = qrySbranch
        ddlData.DataTextField = "BRANCHNAME"
        ddlData.DataValueField = "BRANCHCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qrySbranch = Nothing


    End Sub
    Public Sub setTSCTypeToDdl_AMLO101(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO101Entities, _
                                       Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo101_Entity = objAmloEntity
        Dim qryMTSCTYPE = Nothing
        If (strCondition = "") Then
            qryMTSCTYPE = (From MTSCTYPE In Amlo101_Entity.MTSCTYPE1 Order By MTSCTYPE.SHOWINDEX Ascending
                           Select MTSCTYPE.TYPE_TSC_ID, TYPE_TSC_NAME = MTSCTYPE.TYPE_TSC_ID & " : " & MTSCTYPE.TYPE_TSC_NAME).ToList
        Else
            qryMTSCTYPE = (From MTSCTYPE In Amlo101_Entity.MTSCTYPE1 Where MTSCTYPE.TYPE_TSC_ID = strCondition Order By MTSCTYPE.SHOWINDEX Ascending Select MTSCTYPE.TYPE_TSC_ID, TYPE_TSC_NAME = MTSCTYPE.TYPE_TSC_ID & " : " & MTSCTYPE.TYPE_TSC_NAME).ToList

        End If

        Dim AddItem As New ListItem("** กรุณาเลือกประเภทธุรกรรม **", 0)
        ddlData.DataSource = qryMTSCTYPE
        ddlData.DataTextField = "TYPE_TSC_NAME"
        ddlData.DataValueField = "TYPE_TSC_ID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMTSCTYPE = Nothing


    End Sub

    Public Sub setObjTypeToDdl_AMLO101(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO101Entities, _
                                       Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo101_Entity = objAmloEntity
        'Dim qryObjType As IQueryable
        'If (strCondition = "") Then
        Dim qryObjType = (From MObjTYPE In Amlo101_Entity.MOBJTYPE Order By MObjTYPE.OBJTYPEID Ascending Select MObjTYPE.OBJTYPEID, OBJTYPENAME = MObjTYPE.OBJTYPEID & " : " & MObjTYPE.OBJTYPENAME).ToList

        'Else
        '    qryObjType = (From MObjTYPE In Amlo101_Entity.MOBJTYPE Where MObjTYPE.OBJTYPEID = strCondition Order By Convert.ToInt32(MObjTYPE.OBJTYPEID) Ascending Select MObjTYPE.OBJTYPEID, OBJTYPENAME = MObjTYPE.OBJTYPEID & " : " & MObjTYPE.OBJTYPENAME).ToList

        'End If

        Dim AddItem As New ListItem("** กรุณาเลือกวัตถุประสงค์ **", 0)
        ddlData.DataSource = qryObjType.OrderBy(Function(fn) Integer.Parse(fn.OBJTYPEID))
        ddlData.DataTextField = "OBJTYPENAME"
        ddlData.DataValueField = "OBJTYPEID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If
        qryObjType = Nothing
    End Sub

    Public Sub setDdlTransType_AMLO1059(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim AddItem As ListItem = Nothing
        Dim AMLO1059Entity = New AMLO1059Entities

        Dim qry = From m In AMLO1059Entity.MTSCTYPE_1_05_9 Order By m.TSCTYPEID Ascending
                         Select m.TSCTYPEID, m.TSCTYPENAME

        AddItem = New ListItem(Resources.resClsMasterDropdown.Select_Search, 0)

        ddlData.DataSource = qry.ToList
        ddlData.DataTextField = "TSCTYPENAME"
        ddlData.DataValueField = "TSCTYPEID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        qry = Nothing
        AMLO1059Entity.Dispose()
        AMLO1059Entity = Nothing

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If
    End Sub
#End Region


#Region " Detail "

    Public Sub setPSNRelationToDdl_AMLO101(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO101Entities, _
                                           Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo101_Entity = objAmloEntity
        Dim qryPSNRelation = Nothing
        If (strCondition = "") Then
            qryPSNRelation = (From MPSNRelation In Amlo101_Entity.MPSNRELATION Where MPSNRelation.PSNRELATIONID < 4 Select MPSNRelation.PSNRELATIONID, PSNRELATION = MPSNRelation.PSNRELATIONID & " : " & MPSNRelation.PSNRELATION).ToList
        Else
            qryPSNRelation = (From MPSNRelation In Amlo101_Entity.MPSNRELATION Where MPSNRelation.PSNRELATIONID = strCondition Select MPSNRelation.PSNRELATIONID, PSNRELATION = MPSNRelation.PSNRELATIONID & " : " & MPSNRelation.PSNRELATION).ToList

        End If

        Dim AddItem As New ListItem("** กรุณาระบุบผู้ร่วม **", 0)
        ddlData.DataSource = qryPSNRelation
        ddlData.DataTextField = "PSNRELATION"
        ddlData.DataValueField = "PSNRELATIONID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryPSNRelation = Nothing

    End Sub

    Public Sub setIDTypeToDdl_AMLO101Part1(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO101Entities, _
                                      Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo101_Entity = objAmloEntity
        Dim qryIDType = Nothing

        qryIDType = (From MIDTYPE In Amlo101_Entity.MIDTYPE Where MIDTYPE.AMLO = 1 Select MIDTYPE.IDTYPE, IDTYPENAME = MIDTYPE.IDTYPE & " : " & MIDTYPE.IDTYPENAME).ToList



        Dim AddItem As New ListItem("** กรุณาเลือก ชนิดเลขที่ **", 0)
        ddlData.DataSource = qryIDType
        ddlData.DataTextField = "IDTYPENAME"
        ddlData.DataValueField = "IDTYPE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryIDType = Nothing
    End Sub
    Public Sub setIDTypeToDdl_AMLO101Part2(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO101Entities, _
                                      Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo101_Entity = objAmloEntity
        Dim qryIDType = Nothing
        qryIDType = (From MIDTYPE In Amlo101_Entity.MIDTYPE Where MIDTYPE.AMLO <> 0 Select MIDTYPE.IDTYPE, IDTYPENAME = MIDTYPE.IDTYPE & " : " & MIDTYPE.IDTYPENAME).ToList

        Dim AddItem As New ListItem("** กรุณาเลือก ชนิดเลขที่ **", 0)
        ddlData.DataSource = qryIDType
        ddlData.DataTextField = "IDTYPENAME"
        ddlData.DataValueField = "IDTYPE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryIDType = Nothing
    End Sub
    Public Sub setOfficeOCCToDdl_AMLO101(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO101Entities, _
                                         Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo101_Entity = objAmloEntity
        Dim qryOfficeOCC = Nothing
        If (strCondition = "") Then
            qryOfficeOCC = (From MOFFICEOCC In Amlo101_Entity.MOFFICEOCC Select MOFFICEOCC.OFFICEOCCID, OFFICEOCCNAME = MOFFICEOCC.OFFICEOCCID & " : " & MOFFICEOCC.OFFICEOCCNAME).ToList
        Else
            qryOfficeOCC = (From MOFFICEOCC In Amlo101_Entity.MOFFICEOCC Where MOFFICEOCC.OFFICEOCCID = strCondition Select MOFFICEOCC.OFFICEOCCID, OFFICEOCCNAME = MOFFICEOCC.OFFICEOCCID & " : " & MOFFICEOCC.OFFICEOCCNAME).ToList
        End If

        Dim AddItem As New ListItem("** กรุณาเลือก อาชีพ **", 0)
        ddlData.DataSource = qryOfficeOCC
        ddlData.DataTextField = "OFFICEOCCNAME"
        ddlData.DataValueField = "OFFICEOCCID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryOfficeOCC = Nothing

    End Sub

    Public Sub setOFFICETYPEToDdl_AMLO101(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO101Entities, _
                                          Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo101_Entity = objAmloEntity
        Dim qryOFFICETYPE = Nothing
        If (strCondition = "") Then
            qryOFFICETYPE = (From MOFFICETYPE In Amlo101_Entity.MOFFICETYPE Select MOFFICETYPE.OFFICETYPEID, OFFICETYPENAME = MOFFICETYPE.OFFICETYPEID & " : " & MOFFICETYPE.OFFICETYPENAME).ToList
        Else
            qryOFFICETYPE = (From MOFFICETYPE In Amlo101_Entity.MOFFICETYPE Where MOFFICETYPE.OFFICETYPEID = strCondition).ToList
        End If

        Dim AddItem As New ListItem("** กรุณาเลือกประเภทประกอบการ **", 0)
        ddlData.DataSource = qryOFFICETYPE
        ddlData.DataTextField = "OFFICETYPENAME"
        ddlData.DataValueField = "OFFICETYPEID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryOFFICETYPE = Nothing


    End Sub

    Public Sub setTypeIDToDdl_AMLO101(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO101Entities, _
                                      Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo101_Entity = objAmloEntity
        Dim qryTypeID = Nothing
        If (strCondition = "") Then
            qryTypeID = (From MIDTYPE In Amlo101_Entity.TYPE_ID Select MIDTYPE.TYPE_ID1, TYPE_NAME = MIDTYPE.TYPE_ID1 & " : " & MIDTYPE.TYPE_NAME).ToList
        Else
            qryTypeID = (From MIDTYPE In Amlo101_Entity.TYPE_ID Where MIDTYPE.TYPE_ID1 = strCondition Select MIDTYPE.TYPE_ID1, TYPE_NAME = MIDTYPE.TYPE_ID1 & " : " & MIDTYPE.TYPE_NAME).ToList
        End If

        Dim AddItem As New ListItem("** กรุณาเลือก หลักฐานทำธุรกรรม **", 0)
        ddlData.DataSource = qryTypeID
        ddlData.DataTextField = "TYPE_NAME"
        ddlData.DataValueField = "TYPE_ID1"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryTypeID = Nothing
    End Sub
#End Region

#Region " GetData "

#Region " Master "
    Public Function getObjTypeName_AMLO101(ByVal objAmloEntity As AMLO101Entities, ByVal strCondition As String) As String
        Amlo101_Entity = objAmloEntity
        Dim strObjType As String = ""
        Try
            Dim qryObjType = (From MObjTYPE In Amlo101_Entity.MOBJTYPE Where MObjTYPE.OBJTYPEID = strCondition Select MObjTYPE.OBJTYPENAME).Single
            strObjType = qryObjType
            qryObjType = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strObjType
    End Function
#End Region

#Region " Detail "

    Public Function getTypeID_AMLO101(ByVal objAmloEntity As AMLO101Entities, ByVal strCondition As String) As String
        Amlo101_Entity = objAmloEntity
        Dim strObjType As String = ""
        Try
            Dim qryObjType = (From TYPEID In Amlo101_Entity.TYPE_ID Where TYPEID.TYPE_ID1 = strCondition Select TYPEID.TYPE_NAME).Single
            strObjType = qryObjType
            qryObjType = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strObjType
    End Function

    Public Function getOfficeOcc_AMLO101(ByVal objAmloEntity As AMLO101Entities, ByVal strCondition As String) As String
        Amlo101_Entity = objAmloEntity
        Dim strOfficeOCC As String = ""
        Try
            Dim qryOfficeOCC = (From MOFFICEOCC In Amlo101_Entity.MOFFICEOCC Where MOFFICEOCC.OFFICEOCCID = strCondition Select MOFFICEOCC.OFFICEOCCNAME).Single
            strOfficeOCC = qryOfficeOCC
            qryOfficeOCC = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strOfficeOCC
    End Function

    Public Function getOfficeType_AMLO101(ByVal objAmloEntity As AMLO101Entities, ByVal strCondition As String) As String
        Amlo101_Entity = objAmloEntity
        Dim strOfficeType As String = ""
        Try
            Dim qryOFFICETYPE = (From MOFFICETYPE In Amlo101_Entity.MOFFICETYPE Where MOFFICETYPE.OFFICETYPEID = strCondition Select MOFFICETYPE.OFFICETYPENAME).Single
            strOfficeType = qryOFFICETYPE
            qryOFFICETYPE = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strOfficeType
    End Function

#End Region

#End Region


#End Region

    Dim Amlo102_Entity As AMLO102Entities = Nothing

#Region " AMLO102"

#Region "DropDown Master"
    Public Sub setBranchToDdl_AMLO102(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO102Entities, _
                                          Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo102_Entity = objAmloEntity
        Dim qrySbranch = Nothing
        If (strCondition = "") Then
            qrySbranch = (From sBranch In Amlo102_Entity.SBRANCH Select sBranch.BRANCHCODE, BRANCHNAME = sBranch.BRANCHCODE & " : " & sBranch.BRANCHNAME).ToList
        Else
            qrySbranch = (From sBranch In Amlo102_Entity.SBRANCH Where sBranch.DEPTCODE = strCondition).ToList

        End If

        Dim AddItem As New ListItem(Resources.resUser.SelectBranch, 0)
        ddlData.DataSource = qrySbranch
        ddlData.DataTextField = "BRANCHNAME"
        ddlData.DataValueField = "BRANCHCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qrySbranch = Nothing


    End Sub
    Public Sub setBranchToDdl_AMLO102Search(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO102Entities, _
                                     Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo102_Entity = objAmloEntity
        Dim qrySbranch = Nothing
        If (strCondition = "") Then
            qrySbranch = (From sBranch In Amlo102_Entity.SBRANCH Select sBranch.BRANCHCODE, BRANCHNAME = sBranch.BRANCHCODE & " : " & sBranch.BRANCHNAME).ToList
        Else
            qrySbranch = (From sBranch In Amlo102_Entity.SBRANCH Where sBranch.DEPTCODE = strCondition Select sBranch.BRANCHCODE, BRANCHNAME = sBranch.BRANCHCODE & " : " & sBranch.BRANCHNAME).ToList

        End If

        Dim AddItem As New ListItem(Resources.resUser.SelectBranchSearch, 0)
        ddlData.DataSource = qrySbranch
        ddlData.DataTextField = "BRANCHNAME"
        ddlData.DataValueField = "BRANCHCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qrySbranch = Nothing


    End Sub
    Public Sub setTSCTypeToDdl_AMLO102(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO102Entities, _
                                       Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")

        Amlo102_Entity = objAmloEntity
        Dim qryMTSCTYPE = Nothing
        If (strCondition = "") Then
            qryMTSCTYPE = (From MTSCTYPE In Amlo102_Entity.MTSCTYPE2 Select MTSCTYPE.TSCTYPEID, TSCTYPENAME = MTSCTYPE.TSCTYPEID & " : " & MTSCTYPE.TSCTYPENAME).ToList
        Else
            qryMTSCTYPE = (From MTSCTYPE In Amlo102_Entity.MTSCTYPE2 Where MTSCTYPE.TSCTYPEID = strCondition Select MTSCTYPE.TSCTYPEID, TSCTYPENAME = MTSCTYPE.TSCTYPEID & " : " & MTSCTYPE.TSCTYPENAME).ToList

        End If

        Dim AddItem As New ListItem("** กรุณาเลือกประเภทธุรกรรม **", 0)
        With ddlData
            .DataSource = qryMTSCTYPE
            .DataTextField = "TSCTYPENAME"
            .DataValueField = "TSCTYPEID"
            .DataBind()
            .Items.Insert(0, AddItem)

            If Not (selectData = "") Then
                .SelectedValue = selectData
            End If
        End With
        qryMTSCTYPE = Nothing


    End Sub

    Public Sub setAssetTypeToDdl_AMLO102(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO102Entities, Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")

        Amlo102_Entity = objAmloEntity
        Dim qryAssetType = Nothing
        If (strCondition = "") Then
            qryAssetType = (From MASSETTYPE In Amlo102_Entity.MASSETTYPE Select MASSETTYPE.ASSETTYPEID, ASSETTYPE = MASSETTYPE.ASSETTYPEID & " : " & MASSETTYPE.ASSETTYPE).ToList
        Else
            qryAssetType = (From MASSETTYPE In Amlo102_Entity.MASSETTYPE Where MASSETTYPE.ASSETTYPEID = strCondition Select MASSETTYPE.ASSETTYPEID, ASSETTYPE = MASSETTYPE.ASSETTYPEID & " : " & MASSETTYPE.ASSETTYPE).ToList

        End If

        Dim AddItem As New ListItem("** กรุณาเลือกชนิดทรัพย์สิน **", 0)
        ddlData.DataSource = qryAssetType
        ddlData.DataTextField = "ASSETTYPE"
        ddlData.DataValueField = "ASSETTYPEID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryAssetType = Nothing

    End Sub

    Public Sub setObjTypeToDdl_AMLO102(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO102Entities, _
                                       Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")

        Amlo102_Entity = objAmloEntity
        Dim qryObjType = Nothing
        If (strCondition = "") Then
            qryObjType = (From MObjTYPE In Amlo102_Entity.MOBJTYPE Select MObjTYPE.OBJTYPEID, OBJTYPENAME = MObjTYPE.OBJTYPEID & " : " & MObjTYPE.OBJTYPENAME).ToList
        Else
            qryObjType = (From MObjTYPE In Amlo102_Entity.MOBJTYPE Where MObjTYPE.OBJTYPEID = strCondition Select MObjTYPE.OBJTYPEID, OBJTYPENAME = MObjTYPE.OBJTYPEID & " : " & MObjTYPE.OBJTYPENAME).ToList

        End If

        Dim AddItem As New ListItem("** กรุณาเลือกวัตถุประสงค์ **", 0)
        ddlData.DataSource = qryObjType
        ddlData.DataTextField = "OBJTYPENAME"
        ddlData.DataValueField = "OBJTYPEID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryObjType = Nothing


    End Sub

    Public Sub setRefTypeToDdl_AMLO102(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO102Entities, _
                                       Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")

        Amlo102_Entity = objAmloEntity
        Dim qryRefType = Nothing
        If (strCondition = "") Then
            qryRefType = (From MRefTYPE In Amlo102_Entity.MRELATION Select MRefTYPE.RELATIONID, RELATIONNAME = MRefTYPE.RELATIONID & " : " & MRefTYPE.RELATIONNAME).ToList
        Else
            qryRefType = (From MRefTYPE In Amlo102_Entity.MRELATION Where MRefTYPE.RELATIONID = strCondition Select MRefTYPE.RELATIONID, RELATIONNAME = MRefTYPE.RELATIONID & " : " & MRefTYPE.RELATIONNAME).ToList

        End If

        Dim AddItem As New ListItem("ความเกี่ยวข้อง", 0)
        ddlData.DataSource = qryRefType
        ddlData.DataTextField = "RELATIONNAME"
        ddlData.DataValueField = "RELATIONID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryRefType = Nothing

    End Sub
#End Region

#Region " Dropdown Detail "

    Sub setPSNRelationToDdl_AMLO102(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO102Entities, _
                                               Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo102_Entity = objAmloEntity
        Dim qryPSNRelation = Nothing
        If (strCondition = "") Then
            qryPSNRelation = (From MPSNRelation In Amlo102_Entity.MPSNRELATION Where MPSNRelation.PSNRELATIONID < 4 Select MPSNRelation.PSNRELATIONID, PSNRELATION = MPSNRelation.PSNRELATIONID & " : " & MPSNRelation.PSNRELATION).ToList
        Else
            qryPSNRelation = (From MPSNRelation In Amlo102_Entity.MPSNRELATION Where MPSNRelation.PSNRELATIONID = strCondition Select MPSNRelation.PSNRELATIONID, PSNRELATION = MPSNRelation.PSNRELATIONID & " : " & MPSNRelation.PSNRELATION).ToList

        End If

        Dim AddItem As New ListItem("** กรุณาระบุบผู้ร่วม **", 0)
        ddlData.DataSource = qryPSNRelation
        ddlData.DataTextField = "PSNRELATION"
        ddlData.DataValueField = "PSNRELATIONID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryPSNRelation = Nothing

    End Sub

    Public Sub setIDTypeToDdl_AMLO102Part1(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO102Entities, _
                                      Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo102_Entity = objAmloEntity
        Dim qryIDType = Nothing

        qryIDType = (From MIDTYPE In Amlo102_Entity.MIDTYPE Where MIDTYPE.AMLO = 1 Select MIDTYPE.IDTYPE, IDTYPENAME = MIDTYPE.IDTYPE & " : " & MIDTYPE.IDTYPENAME).ToList



        Dim AddItem As New ListItem("** กรุณาเลือก ชนิดเลขที่ **", 0)
        ddlData.DataSource = qryIDType
        ddlData.DataTextField = "IDTYPENAME"
        ddlData.DataValueField = "IDTYPE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryIDType = Nothing

    End Sub

    Public Sub setIDTypeToDdl_AMLO102Part2(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO102Entities, _
                                     Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo102_Entity = objAmloEntity
        Dim qryIDType = Nothing

        qryIDType = (From MIDTYPE In Amlo102_Entity.MIDTYPE Where MIDTYPE.AMLO <> 0 Select MIDTYPE.IDTYPE, IDTYPENAME = MIDTYPE.IDTYPE & " : " & MIDTYPE.IDTYPENAME).ToList


        Dim AddItem As New ListItem("** กรุณาเลือก ชนิดเลขที่ **", 0)
        ddlData.DataSource = qryIDType
        ddlData.DataTextField = "IDTYPENAME"
        ddlData.DataValueField = "IDTYPE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryIDType = Nothing

    End Sub

    Public Sub setOfficeOCCToDdl_AMLO102(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO102Entities, _
                                         Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")

        Amlo102_Entity = objAmloEntity
        Dim qryOfficeOCC = Nothing
        If (strCondition = "") Then
            qryOfficeOCC = (From MOFFICEOCC In Amlo102_Entity.MOFFICEOCC Select MOFFICEOCC.OFFICEOCCID, OFFICEOCCNAME = MOFFICEOCC.OFFICEOCCID & " : " & MOFFICEOCC.OFFICEOCCNAME).ToList
        Else
            qryOfficeOCC = (From MOFFICEOCC In Amlo102_Entity.MOFFICEOCC Where MOFFICEOCC.OFFICEOCCID = strCondition Select MOFFICEOCC.OFFICEOCCID, OFFICEOCCNAME = MOFFICEOCC.OFFICEOCCID & " : " & MOFFICEOCC.OFFICEOCCNAME).ToList
        End If

        Dim AddItem As New ListItem("** กรุณาเลือก อาชีพ **", 0)
        ddlData.DataSource = qryOfficeOCC
        ddlData.DataTextField = "OFFICEOCCNAME"
        ddlData.DataValueField = "OFFICEOCCID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryOfficeOCC = Nothing


    End Sub
    Public Sub setOFFICETYPEToDdl_AMLO102(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO102Entities, _
                                          Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo102_Entity = objAmloEntity
        Dim qryOFFICETYPE = Nothing
        If (strCondition = "") Then
            qryOFFICETYPE = (From MOFFICETYPE In Amlo102_Entity.MOFFICETYPE Select MOFFICETYPE.OFFICETYPEID, OFFICETYPENAME = MOFFICETYPE.OFFICETYPEID & " : " & MOFFICETYPE.OFFICETYPENAME).ToList
        Else
            qryOFFICETYPE = (From MOFFICETYPE In Amlo102_Entity.MOFFICETYPE Where MOFFICETYPE.OFFICETYPEID = strCondition Select MOFFICETYPE.OFFICETYPEID, OFFICETYPENAME = MOFFICETYPE.OFFICETYPEID & " : " & MOFFICETYPE.OFFICETYPENAME).ToList
        End If

        Dim AddItem As New ListItem("** กรุณาเลือกประเภทประกอบการ **", 0)
        ddlData.DataSource = qryOFFICETYPE
        ddlData.DataTextField = "OFFICETYPENAME"
        ddlData.DataValueField = "OFFICETYPEID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryOFFICETYPE = Nothing


    End Sub

    Public Sub setTypeIDToDdl_AMLO102(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO102Entities, _
                                      Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo102_Entity = objAmloEntity
        Dim qryTypeID = Nothing
        If (strCondition = "") Then
            qryTypeID = (From MIDTYPE In Amlo102_Entity.TYPE_ID Select MIDTYPE.TYPE_ID1, TYPE_NAME = MIDTYPE.TYPE_ID1 & " : " & MIDTYPE.TYPE_NAME).ToList
        Else
            qryTypeID = (From MIDTYPE In Amlo102_Entity.TYPE_ID Where MIDTYPE.TYPE_ID1 = strCondition Select MIDTYPE.TYPE_ID1, TYPE_NAME = MIDTYPE.TYPE_ID1 & " : " & MIDTYPE.TYPE_NAME).ToList
        End If

        Dim AddItem As New ListItem("** กรุณาเลือก หลักฐานทำธุรกรรม **", 0)
        ddlData.DataSource = qryTypeID
        ddlData.DataTextField = "TYPE_NAME"
        ddlData.DataValueField = "TYPE_ID1"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryTypeID = Nothing

    End Sub
#End Region

#Region "GetData"


#Region " Master "

    Public Function getTSCTypeName_AMLO102(ByVal objAmloEntity As AMLO102Entities, ByVal strCondition As String) As String
        Amlo102_Entity = objAmloEntity
        Dim strTSCName As String = ""
        Try
            Dim qryTSCType = (From MTSCTYPE In Amlo102_Entity.MTSCTYPE2 Where MTSCTYPE.TSCTYPEID = strCondition Select MTSCTYPE.TSCTYPENAME).Single
            strTSCName = qryTSCType
            qryTSCType = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strTSCName
    End Function

    Public Function getObjTypeName_AMLO102(ByVal objAmloEntity As AMLO102Entities, ByVal strCondition As String) As String
        Amlo102_Entity = objAmloEntity
        Dim strObjType As String = ""
        Try
            Dim qryObjType = (From MObjTYPE In Amlo102_Entity.MOBJTYPE Where MObjTYPE.OBJTYPEID = strCondition Select MObjTYPE.OBJTYPENAME).Single
            strObjType = qryObjType
            qryObjType = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strObjType
    End Function

    Public Function getRefTypeName_AMLO102(ByVal objAmloEntity As AMLO102Entities, ByVal strCondition As String) As String
        Amlo102_Entity = objAmloEntity
        Dim strRefName As String = ""
        Try
            Dim qryRefType = (From MRefTYPE In Amlo102_Entity.MRELATION Where MRefTYPE.RELATIONID = strCondition Select MRefTYPE.RELATIONNAME).Single
            strRefName = qryRefType
            qryRefType = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strRefName
    End Function



#End Region

#Region " Detail "
    Public Function getTypeID_AMLO102(ByVal objAmloEntity As AMLO102Entities, ByVal strCondition As String) As String
        Amlo102_Entity = objAmloEntity
        Dim strObjType As String = ""
        Try
            Dim qryObjType = (From TYPEID In Amlo102_Entity.TYPE_ID Where TYPEID.TYPE_ID1 = strCondition Select TYPEID.TYPE_NAME).Single
            strObjType = qryObjType
            qryObjType = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strObjType
    End Function

    Public Function getOfficeOcc_AMLO102(ByVal objAmloEntity As AMLO102Entities, ByVal strCondition As String) As String
        Amlo102_Entity = objAmloEntity
        Dim strOfficeOCC As String = ""
        Try
            Dim qryOfficeOCC = (From MOFFICEOCC In Amlo102_Entity.MOFFICEOCC Where MOFFICEOCC.OFFICEOCCID = strCondition Select MOFFICEOCC.OFFICEOCCNAME).Single
            strOfficeOCC = qryOfficeOCC
            qryOfficeOCC = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strOfficeOCC
    End Function

    Public Function getOfficeType_AMLO102(ByVal objAmloEntity As AMLO102Entities, ByVal strCondition As String) As String
        Amlo102_Entity = objAmloEntity
        Dim strOfficeType As String = ""
        Try
            Dim qryOFFICETYPE = (From MOFFICETYPE In Amlo102_Entity.MOFFICETYPE Where MOFFICETYPE.OFFICETYPEID = strCondition Select MOFFICETYPE.OFFICETYPENAME).Single
            strOfficeType = qryOFFICETYPE
            qryOFFICETYPE = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strOfficeType
    End Function

    Public Function getRelation_AMLO102(ByVal objAmloEntity As AMLO102Entities, ByVal strCondition As String) As String
        Amlo102_Entity = objAmloEntity
        Dim strRELATIONTYPE As String = ""
        Try
            Dim qryRELATIONTYPE = (From MRELATION In Amlo102_Entity.MRELATION Where MRELATION.RELATIONID = strCondition Select MRELATION.RELATIONNAME).Single
            strRELATIONTYPE = qryRELATIONTYPE
            qryRELATIONTYPE = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strRELATIONTYPE
    End Function

#End Region

#End Region


#End Region

    Dim Amlo103_Entity As AMLO103Entities = Nothing

#Region " AMLO103"

#Region "DropDown Master"

    Public Sub setBranchToDdl_AMLO103(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO103Entities, _
                                            Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo103_Entity = objAmloEntity
        Dim qrySbranch = Nothing
        If (strCondition = "") Then
            qrySbranch = (From sBranch In Amlo103_Entity.SBRANCH Select sBranch.BRANCHCODE, BRANCHNAME = sBranch.BRANCHCODE & " : " & sBranch.BRANCHNAME).ToList
        Else
            qrySbranch = (From sBranch In Amlo103_Entity.SBRANCH Where sBranch.DEPTCODE = strCondition Select sBranch.BRANCHCODE, BRANCHNAME = sBranch.BRANCHCODE & " : " & sBranch.BRANCHNAME).ToList

        End If

        Dim AddItem As New ListItem(Resources.resUser.SelectBranch, 0)
        ddlData.DataSource = qrySbranch
        ddlData.DataTextField = "BRANCHNAME"
        ddlData.DataValueField = "BRANCHCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qrySbranch = Nothing


    End Sub
    Public Sub setBranchToDdl_AMLO103Search(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO103Entities, _
                                     Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo103_Entity = objAmloEntity
        Dim qrySbranch = Nothing
        If (strCondition = "") Then
            qrySbranch = (From sBranch In Amlo103_Entity.SBRANCH Select sBranch.BRANCHCODE, BRANCHNAME = sBranch.BRANCHCODE & " : " & sBranch.BRANCHNAME).ToList
        Else
            qrySbranch = (From sBranch In Amlo103_Entity.SBRANCH Where sBranch.DEPTCODE = strCondition Select sBranch.BRANCHCODE, BRANCHNAME = sBranch.BRANCHCODE & " : " & sBranch.BRANCHNAME).ToList

        End If

        Dim AddItem As New ListItem(Resources.resUser.SelectBranchSearch, 0)
        ddlData.DataSource = qrySbranch
        ddlData.DataTextField = "BRANCHNAME"
        ddlData.DataValueField = "BRANCHCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qrySbranch = Nothing


    End Sub

    Public Sub setTSCTypeToDdl_AMLO103(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO103Entities, _
                                      Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")

        Amlo103_Entity = objAmloEntity
        Dim qryMTSCTYPE = Nothing
        If (strCondition = "") Then
            qryMTSCTYPE = (From MTSCTYPE In Amlo103_Entity.MTSCTYPE3 Select MTSCTYPE.TSCTYPEID, TSCTYPENAME = MTSCTYPE.TSCTYPEID & " : " & MTSCTYPE.TSCTYPENAME).ToList
        Else
            qryMTSCTYPE = (From MTSCTYPE In Amlo103_Entity.MTSCTYPE3 Where MTSCTYPE.TSCTYPEID = strCondition Select MTSCTYPE.TSCTYPEID, TSCTYPENAME = MTSCTYPE.TSCTYPEID & " : " & MTSCTYPE.TSCTYPENAME).ToList

        End If

        Dim AddItem As New ListItem("** กรุณาเลือกประเภทธุรกรรม **", 0)
        With ddlData
            .DataSource = qryMTSCTYPE
            .DataTextField = "TSCTYPENAME"
            .DataValueField = "TSCTYPEID"
            .DataBind()
            .Items.Insert(0, AddItem)

            If Not (selectData = "") Then
                .SelectedValue = selectData
            End If
        End With
        qryMTSCTYPE = Nothing


    End Sub

    Public Sub setObjTypeToDdl_AMLO103(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO103Entities, _
                                          Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")

        Amlo103_Entity = objAmloEntity
        Dim qryObjType = Nothing
        If (strCondition = "") Then
            qryObjType = (From MObjTYPE In Amlo103_Entity.MOBJTYPE Select MObjTYPE.OBJTYPEID, OBJTYPENAME = MObjTYPE.OBJTYPEID & " : " & MObjTYPE.OBJTYPENAME).ToList
        Else
            qryObjType = (From MObjTYPE In Amlo103_Entity.MOBJTYPE Where MObjTYPE.OBJTYPEID = strCondition Select MObjTYPE.OBJTYPEID, OBJTYPENAME = MObjTYPE.OBJTYPEID & " : " & MObjTYPE.OBJTYPENAME).ToList

        End If

        Dim AddItem As New ListItem("** กรุณาเลือกวัตถุประสงค์ **", 0)
        ddlData.DataSource = qryObjType
        ddlData.DataTextField = "OBJTYPENAME"
        ddlData.DataValueField = "OBJTYPEID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryObjType = Nothing


    End Sub

    Public Sub setRefTypeToDdl_AMLO103(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO103Entities, _
                                       Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")

        Amlo103_Entity = objAmloEntity
        Dim qryRefType = (From MRefTYPE In Amlo103_Entity.MRELATION Select MRefTYPE.RELATIONID, RELATIONNAME = MRefTYPE.RELATIONID & " : " & MRefTYPE.RELATIONNAME).ToList


        Dim AddItem As New ListItem("ความเกี่ยวข้อง", 0)
        ddlData.DataSource = qryRefType
        ddlData.DataTextField = "RELATIONNAME"
        ddlData.DataValueField = "RELATIONID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryRefType = Nothing

    End Sub
#End Region

#Region " Dropdown Detail "


    Sub setPSNRelationToDdl_AMLO103(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO103Entities, _
                                               Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo103_Entity = objAmloEntity
        Dim qryPSNRelation = Nothing
        If (strCondition = "") Then
            qryPSNRelation = (From MPSNRelation In Amlo103_Entity.MPSNRELATION Where MPSNRelation.PSNRELATIONID < 4 Select MPSNRelation.PSNRELATIONID, PSNRELATION = MPSNRelation.PSNRELATIONID & " : " & MPSNRelation.PSNRELATION).ToList
        Else
            qryPSNRelation = (From MPSNRelation In Amlo103_Entity.MPSNRELATION Where MPSNRelation.PSNRELATIONID = strCondition Select MPSNRelation.PSNRELATIONID, PSNRELATION = MPSNRelation.PSNRELATIONID & " : " & MPSNRelation.PSNRELATION).ToList

        End If

        Dim AddItem As New ListItem("** กรุณาระบุบผู้ร่วม **", 0)
        ddlData.DataSource = qryPSNRelation
        ddlData.DataTextField = "PSNRELATION"
        ddlData.DataValueField = "PSNRELATIONID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryPSNRelation = Nothing

    End Sub

    Public Sub setIDTypeToDdl_AMLO103Part1(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO103Entities, _
                                      Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo103_Entity = objAmloEntity
        Dim qryIDType = Nothing

        qryIDType = (From MIDTYPE In Amlo103_Entity.MIDTYPE Where MIDTYPE.AMLO = 1 Select MIDTYPE.IDTYPE, IDTYPENAME = MIDTYPE.IDTYPE & " : " & MIDTYPE.IDTYPENAME).ToList



        Dim AddItem As New ListItem("** กรุณาเลือก ชนิดเลขที่ **", 0)
        ddlData.DataSource = qryIDType
        ddlData.DataTextField = "IDTYPENAME"
        ddlData.DataValueField = "IDTYPE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryIDType = Nothing

    End Sub

    Public Sub setIDTypeToDdl_AMLO103Part2(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO103Entities, _
                                     Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo103_Entity = objAmloEntity
        Dim qryIDType = Nothing

        qryIDType = (From MIDTYPE In Amlo103_Entity.MIDTYPE Where MIDTYPE.AMLO <> 0 Select MIDTYPE.IDTYPE, IDTYPENAME = MIDTYPE.IDTYPE & " : " & MIDTYPE.IDTYPENAME).ToList


        Dim AddItem As New ListItem("** กรุณาเลือก ชนิดเลขที่ **", 0)
        ddlData.DataSource = qryIDType
        ddlData.DataTextField = "IDTYPENAME"
        ddlData.DataValueField = "IDTYPE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryIDType = Nothing

    End Sub

    Public Sub setOfficeOCCToDdl_AMLO103(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO103Entities, _
                                         Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")

        Amlo103_Entity = objAmloEntity
        Dim qryOfficeOCC = Nothing
        If (strCondition = "") Then
            qryOfficeOCC = (From MOFFICEOCC In Amlo103_Entity.MOFFICEOCC Select MOFFICEOCC.OFFICEOCCID, OFFICEOCCNAME = MOFFICEOCC.OFFICEOCCID & " : " & MOFFICEOCC.OFFICEOCCNAME).ToList
        Else
            qryOfficeOCC = (From MOFFICEOCC In Amlo103_Entity.MOFFICEOCC Where MOFFICEOCC.OFFICEOCCID = strCondition Select MOFFICEOCC.OFFICEOCCID, OFFICEOCCNAME = MOFFICEOCC.OFFICEOCCID & " : " & MOFFICEOCC.OFFICEOCCNAME).ToList
        End If

        Dim AddItem As New ListItem("** กรุณาเลือก อาชีพ **", 0)
        ddlData.DataSource = qryOfficeOCC
        ddlData.DataTextField = "OFFICEOCCNAME"
        ddlData.DataValueField = "OFFICEOCCID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryOfficeOCC = Nothing


    End Sub
    Public Sub setOFFICETYPEToDdl_AMLO103(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO103Entities, _
                                          Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo103_Entity = objAmloEntity
        Dim qryOFFICETYPE = Nothing
        If (strCondition = "") Then
            qryOFFICETYPE = (From MOFFICETYPE In Amlo103_Entity.MOFFICETYPE Select MOFFICETYPE.OFFICETYPEID, OFFICETYPENAME = MOFFICETYPE.OFFICETYPEID & " : " & MOFFICETYPE.OFFICETYPENAME).ToList
        Else
            qryOFFICETYPE = (From MOFFICETYPE In Amlo103_Entity.MOFFICETYPE Where MOFFICETYPE.OFFICETYPEID = strCondition Select MOFFICETYPE.OFFICETYPEID, OFFICETYPENAME = MOFFICETYPE.OFFICETYPEID & " : " & MOFFICETYPE.OFFICETYPENAME).ToList
        End If

        Dim AddItem As New ListItem("** กรุณาเลือกประเภทประกอบการ **", 0)
        ddlData.DataSource = qryOFFICETYPE
        ddlData.DataTextField = "OFFICETYPENAME"
        ddlData.DataValueField = "OFFICETYPEID"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryOFFICETYPE = Nothing


    End Sub

    Public Sub setTypeIDToDdl_AMLO103(ByRef ddlData As DropDownList, ByVal objAmloEntity As AMLO103Entities, _
                                      Optional ByVal strCondition As String = "", Optional ByVal selectData As String = "")
        Amlo103_Entity = objAmloEntity
        Dim qryTypeID = Nothing
        If (strCondition = "") Then
            qryTypeID = (From MIDTYPE In Amlo103_Entity.TYPE_ID Select MIDTYPE.TYPE_ID1, TYPE_NAME = MIDTYPE.TYPE_ID1 & " : " & MIDTYPE.TYPE_NAME).ToList
        Else
            qryTypeID = (From MIDTYPE In Amlo103_Entity.TYPE_ID Where MIDTYPE.TYPE_ID1 = strCondition Select MIDTYPE.TYPE_ID1, TYPE_NAME = MIDTYPE.TYPE_ID1 & " : " & MIDTYPE.TYPE_NAME).ToList
        End If

        Dim AddItem As New ListItem("** กรุณาเลือก หลักฐานทำธุรกรรม **", 0)
        ddlData.DataSource = qryTypeID
        ddlData.DataTextField = "TYPE_NAME"
        ddlData.DataValueField = "TYPE_ID1"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryTypeID = Nothing

    End Sub
#End Region

#Region "GetData"


#Region " Master "

    Public Function getTSCTypeName_AMLO103(ByVal objAmloEntity As AMLO103Entities, ByVal strCondition As String) As String
        Amlo103_Entity = objAmloEntity
        Dim strTSCName As String = ""
        Try
            Dim qryTSCType = (From MTSCTYPE In Amlo103_Entity.MTSCTYPE3 Where MTSCTYPE.TSCTYPEID = strCondition Select MTSCTYPE.TSCTYPENAME).Single
            strTSCName = qryTSCType
            qryTSCType = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strTSCName
    End Function

    Public Function getObjTypeName_AMLO103(ByVal objAmloEntity As AMLO103Entities, ByVal strCondition As String) As String
        Amlo103_Entity = objAmloEntity
        Dim strObjType As String = ""
        Try
            Dim qryObjType = (From MObjTYPE In Amlo103_Entity.MOBJTYPE Where MObjTYPE.OBJTYPEID = strCondition Select MObjTYPE.OBJTYPENAME).Single
            strObjType = qryObjType
            qryObjType = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strObjType
    End Function

    Public Function getRefTypeName_AMLO103(ByVal objAmloEntity As AMLO103Entities, ByVal strCondition As String) As String
        Amlo103_Entity = objAmloEntity
        Dim strRefName As String = ""
        Try
            Dim qryRefType = (From MRefTYPE In Amlo103_Entity.MRELATION Where MRefTYPE.RELATIONID = strCondition Select MRefTYPE.RELATIONNAME).Single
            strRefName = qryRefType
            qryRefType = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strRefName
    End Function



#End Region

#Region " Detail "
    Public Function getTypeID_AMLO103(ByVal objAmloEntity As AMLO103Entities, ByVal strCondition As String) As String
        Amlo103_Entity = objAmloEntity
        Dim strObjType As String = ""
        Try
            Dim qryObjType = (From TYPEID In Amlo103_Entity.TYPE_ID Where TYPEID.TYPE_ID1 = strCondition Select TYPEID.TYPE_NAME).Single
            strObjType = qryObjType
            qryObjType = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strObjType
    End Function

    Public Function getOfficeOcc_AMLO103(ByVal objAmloEntity As AMLO103Entities, ByVal strCondition As String) As String
        Amlo103_Entity = objAmloEntity
        Dim strOfficeOCC As String = ""
        Try
            Dim qryOfficeOCC = (From MOFFICEOCC In Amlo103_Entity.MOFFICEOCC Where MOFFICEOCC.OFFICEOCCID = strCondition Select MOFFICEOCC.OFFICEOCCNAME).Single
            strOfficeOCC = qryOfficeOCC
            qryOfficeOCC = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strOfficeOCC
    End Function

    Public Function getOfficeType_AMLO103(ByVal objAmloEntity As AMLO103Entities, ByVal strCondition As String) As String
        Amlo103_Entity = objAmloEntity
        Dim strOfficeType As String = ""
        Try
            Dim qryOFFICETYPE = (From MOFFICETYPE In Amlo103_Entity.MOFFICETYPE Where MOFFICETYPE.OFFICETYPEID = strCondition Select MOFFICETYPE.OFFICETYPENAME).Single
            strOfficeType = qryOFFICETYPE
            qryOFFICETYPE = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strOfficeType
    End Function

    Public Function getRelation_AMLO103(ByVal objAmloEntity As AMLO103Entities, ByVal strCondition As String) As String
        Amlo103_Entity = objAmloEntity
        Dim strRELATIONTYPE As String = ""
        Try
            Dim qryRELATIONTYPE = (From MRELATION In Amlo103_Entity.MRELATION Where MRELATION.RELATIONID = strCondition Select MRELATION.RELATIONNAME).Single
            strRELATIONTYPE = qryRELATIONTYPE
            qryRELATIONTYPE = Nothing
        Catch ex As Exception
            Throw ex
        End Try
        Return strRELATIONTYPE
    End Function
#End Region

#End Region


#End Region


    '--------- KYC----------
#Region "Master KYC"

#Region "ID Type"

    Public Sub setIDTypeToDdl(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMID = (From MID In kycEntity.MIDTYPE
                           Where MID.KYC = 1
                           Order By MID.IDTYPE).ToList

        ddlData.DataSource = qryMID
        ddlData.DataTextField = "IDTYPENAME"
        ddlData.DataValueField = "IDTYPE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, "")

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMID = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub

#End Region

#Region "Prefix"

    Public Sub setPrefixTHToDdl(ByRef ddlData As DropDownList, ByVal strCondition As Integer, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMPrefix = Nothing



        If (strCondition = 1) Then
            qryMPrefix = (From MPrefix In kycEntity.MPREFIX
                            Where MPrefix.PREFIXTYPE = strCondition
                            Order By MPrefix.PREFIXCODE Ascending).ToList
        ElseIf (strCondition = 2) Then
            qryMPrefix = (From MPrefix In kycEntity.MPREFIX
                            Where MPrefix.PREFIXTYPE = strCondition
                            Order By MPrefix.PREFIXTH Ascending).ToList

        End If

        ddlData.DataSource = qryMPrefix
        ddlData.DataTextField = "PREFIXTH"
        ddlData.DataValueField = "PREFIXCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, "")

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMPrefix = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub

    Public Sub setPrefixENToDdl(ByRef ddlData As DropDownList, ByVal strCondition As Integer, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMPrefix = (From MPrefix In kycEntity.MPREFIX
                          Where MPrefix.PREFIXTYPE = strCondition
                          Order By MPrefix.PREFIXCODE Ascending).ToList

        ddlData.DataSource = qryMPrefix
        ddlData.DataTextField = "PREFIXEN"
        ddlData.DataValueField = "PREFIXCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, "")

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMPrefix = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub

#End Region

#Region "Occupation"

    Public Sub setOccupationToDdl(ByRef ddlData As DropDownList, ByVal strCondition As String, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMOCCUPATION = (From MOcc In kycEntity.MOCCUPATION
                              Where MOcc.OCCTYPE = strCondition
                              Order By MOcc.OCCCODE).ToList

        ddlData.DataSource = qryMOCCUPATION
        ddlData.DataTextField = "OCCNAME"
        ddlData.DataValueField = "OCCCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, "")


        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMOCCUPATION = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub

#End Region

#Region "Business"

    Public Sub setBusinessToDdl(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMBusiness = (From MBiz In kycEntity.MBUSINESS Order By MBiz.BIZNAME).ToList

        'ddlData.DataSource = qryMBusiness
        'ddlData.DataTextField = "BIZNAME"
        'ddlData.DataValueField = "BIZCODE"
        'ddlData.DataBind()
        'ddlData.Items.Insert(0, "")

        Dim AddItem As New ListItem("", 0)
        ddlData.DataSource = qryMBusiness
        ddlData.DataTextField = "BIZNAME"
        ddlData.DataValueField = "BIZCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)


        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMBusiness = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub

#End Region

#Region "Approve"

    Public Sub setApproveToDdl(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMApprove = (From MAPPROVE In kycEntity.MAPPROVESTATUS
                           Where MAPPROVE.STATUS = False
                           Order By MAPPROVE.APPROVECODE).ToList

        ddlData.DataSource = qryMApprove
        ddlData.DataTextField = "APPROVENAME"
        ddlData.DataValueField = "APPROVECODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, "")

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMApprove = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub

#End Region

#Region "Nationality"

    Public Sub setNationalityToDdl(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMNationality = (From MNation In kycEntity.MNATIONALITY Order By MNation.NATIONALITYNAME).ToList

        ddlData.DataSource = qryMNationality
        ddlData.DataTextField = "NATIONALITYNAME"
        ddlData.DataValueField = "NATIONCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, "")

        ddlData.SelectedValue = 202

        qryMNationality = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub

    Public Sub setNationalityToDdl(ByRef ddlData As ASPxComboBox, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMNationality = (From MNation In kycEntity.MNATIONALITY Order By MNation.NATIONALITYNAME).ToList
        ddlData.Items.Add("", 0)
        ddlData.DataSource = qryMNationality
        ddlData.TextField = "NATIONALITYNAME"
        ddlData.ValueField = "NATIONCODE"
        ddlData.DataBind()
        ddlData.Value = "202"

        qryMNationality = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing
    End Sub

#End Region

#Region "County"

    Public Sub setCountyToDdl(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMNationality = (From MNation In kycEntity.MNATIONALITY Order By MNation.NATIONCODE).ToList

        ddlData.DataSource = qryMNationality
        ddlData.DataTextField = "COUNTYNAME"
        ddlData.DataValueField = "NATIONCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, "")

        qryMNationality = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub

#End Region

#Region "Check Evidence"
    Public Sub setCheckToDdl(ByRef ddlData As DropDownList, ByVal strCondition As String, ByVal strCondition1 As String, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMCheck = From MCheck In kycEntity.MCHECKEVIDENCE
                            Order By MCheck.TYPE Ascending, MCheck.SORTSEQ Ascending
        If Not (strCondition1 = "") Then
            qryMCheck = qryMCheck.Where(Function(c) c.TYPE = CInt(strCondition) Or c.TYPE = CInt(strCondition1))
        Else
            qryMCheck = qryMCheck.Where(Function(c) c.TYPE = CInt(strCondition))
        End If

        ddlData.DataSource = qryMCheck
        ddlData.DataTextField = "CHECKNAME"
        ddlData.DataValueField = "CHECKCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, "")

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMCheck = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub
#End Region

#Region "Gender"
    Public Sub setGenderToDdl(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMGender = From MGender In kycEntity.MGENDER
                            Order By MGender.GENDERCODE Ascending


        ddlData.DataSource = qryMGender
        ddlData.DataTextField = "GENDERNAME"
        ddlData.DataValueField = "GENDERCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, "")

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMGender = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub
#End Region

#Region "MARITAL STATUS"
    Public Sub setMaritalToDdl(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMMARITAL = From MMARITAL In kycEntity.MMARITALSTATUS
                            Order By MMARITAL.MARITALCODE Ascending


        ddlData.DataSource = qryMMARITAL
        ddlData.DataTextField = "MARITALNAME"
        ddlData.DataValueField = "MARITALCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, "")

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMMARITAL = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub
#End Region

#Region "MPRODUCT"

    Public Sub setMProductToDdl(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMProduct = From MPRODUCT In kycEntity.MPRODUCT
                            Order By MPRODUCT.PRODUCTCODE Ascending


        ddlData.DataSource = qryMProduct
        ddlData.DataTextField = "PRODUCTNAME"
        ddlData.DataValueField = "PRODUCTCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, "")

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMProduct = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub
#End Region

#Region "MAdditional_Service"

    Public Sub setMAdditional_Service_To_Ddl(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMService = From MAdd_Service In kycEntity.MADDITION_SERVICE
                            Order By MAdd_Service.ADSERVICECODE Ascending

        ddlData.DataSource = qryMService
        ddlData.DataTextField = "ADSERVICENAME"
        ddlData.DataValueField = "ADSERVICECODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, "")

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMService = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub

#End Region

#Region "MCORP_CATEGERY"

    Public Sub setOtherDoc_To_Ddl(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")

        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMCorpCate = From MAdd_Category In kycEntity.MOTHER_DOC
                       Order By MAdd_Category.DOC_DESCRIPTION Ascending

        ddlData.DataSource = qryMCorpCate
        ddlData.DataTextField = "DOC_DESCRIPTION"
        ddlData.DataValueField = "DOC_CODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, "")

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMCorpCate = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub

#End Region

#Region "Position"
    Public Sub setPositionToDdl(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMPosition = From MPOSITION In kycEntity.MPOSITION
                            Order By MPOSITION.POCODE Ascending


        ddlData.DataSource = qryMPosition
        ddlData.DataTextField = "PONAME"
        ddlData.DataValueField = "POCODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, "")

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMPosition = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub
#End Region

#Region "CustSubType"

    Public Sub setSubTypeToDdl(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMType = (From t In kycEntity.MCUSTSUBTYPE
                        Where Not t.CUSTSUBTYPE = 1
                           Order By t.CUSTSUBTYPENAME).ToList

        ddlData.DataSource = qryMType
        ddlData.DataTextField = "CUSTSUBTYPENAME"
        ddlData.DataValueField = "CUSTSUBTYPE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, "")

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMType = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub

    Public Sub setMETLStatusToDdl(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMType = (From t In kycEntity.METLSTATUS
                        Order By t.ETL_STATUS).ToList


        Dim AddItem As New ListItem(Resources.resClsMasterDropdown.Select_Search, 0)
        ddlData.DataSource = qryMType
        ddlData.DataTextField = "ETL_STATUSDESC"
        ddlData.DataValueField = "ETL_STATUS"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMType = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub

#End Region

#Region "Biz Relation"

    Public Sub setBizRelationToDdl(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim kycEntity As KYCEntities = New KYCEntities
        Dim qryMBiz = (From b In kycEntity.MBIZRELATION
                           Order By b.BIZRECODE).ToList

        ddlData.DataSource = qryMBiz
        ddlData.DataTextField = "BIZRENAME"
        ddlData.DataValueField = "BIZRECODE"
        ddlData.DataBind()
        ddlData.Items.Insert(0, "")

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If

        qryMBiz = Nothing
        kycEntity.Dispose()
        kycEntity = Nothing

    End Sub

#End Region


#Region " Address "

    Public Sub setProvince(ByRef ddlData As DropDownList, Optional ByVal selectData As String = "")
        Dim ds As DataSet
        Dim AddItem As ListItem = Nothing

        Dim strSql As String = " select ref_code,ref_desc from kycadmin.reference_code_table where ref_rec_type='03' order by ref_desc"
        ds = clsDB.QueryDataSet(strSql, "reference_code_table")

        AddItem = New ListItem(Resources.resClsMasterDropdown.Select_Province, 0)


        ddlData.DataSource = ds.Tables("reference_code_table")
        ddlData.DataTextField = "ref_desc"
        ddlData.DataValueField = "ref_code"
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If


        ds = Nothing


    End Sub

    Public Sub setAmphor(ByRef ddlData As DropDownList, Optional ByVal ProviceCode As String = "", Optional ByVal selectData As String = "")
        Dim ds As DataSet
        Dim AddItem As ListItem = Nothing

        Dim strSql As String = " select ref_code,ref_desc from kycadmin.reference_code_table where ref_rec_type='02'  "

        If Not ProviceCode = "" Then
            strSql = strSql & " and " & " REF_CODE Like '" & ProviceCode & "%' order by REF_desc"
        Else
            strSql = strSql & " order by REF_desc "
        End If

        ds = clsDB.QueryDataSet(strSql, "reference_code_table")

        AddItem = New ListItem(Resources.resClsMasterDropdown.Select_Amphor, 0)

        With ddlData
            .DataSource = ds.Tables("reference_code_table")
            .DataTextField = "ref_desc"
            .DataValueField = "ref_code"
        End With
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If



        ds = Nothing


    End Sub

    Public Sub setOccupation_4(ByRef ddlData As DropDownList, Optional ByVal occCode As String = "", Optional ByVal selectData As String = "")
        Dim ds As DataSet
        Dim AddItem As ListItem = Nothing

        Dim strSql As String = ""

        strSql = ""
        strSql += "  SELECT DISTINCT OCCCODE_SUB,       "
        strSql += "         OCCCODE_SUB_DESC            "
        strSql += "    FROM kycadmin.MOCCUPATION_SUB    "
        strSql += "   WHERE OCCCODE_SUB is not null     "

        If Not occCode = "" Then
            strSql = strSql & " and " & " OCCCODE = '" & occCode & "' order by OCCCODE_SUB_DESC"
        Else
            strSql = strSql & " order by OCCCODE_SUB_DESC "
        End If

        ds = clsDB.QueryDataSet(strSql, "OCCCODE_SUB")

        AddItem = New ListItem("<-กรุณาเลือกรายละเอียดอาชีพ->", 0)


        With ddlData
            .DataSource = ds.Tables("OCCCODE_SUB")
            .DataTextField = "OCCCODE_SUB_DESC"
            .DataValueField = "OCCCODE_SUB"
        End With
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If



        ds = Nothing


    End Sub

    Public Sub setTambol(ByRef ddlData As DropDownList, Optional ByVal AmphorCode As String = "", Optional ByVal selectData As String = "")
        Dim ds As DataSet
        Dim AddItem As ListItem = Nothing

        Dim strSql As String = " select ref_code,ref_desc from kycadmin.reference_code_table where ref_rec_type='01' "

        If Not AmphorCode = "" Then
            strSql = strSql & " and " & " REF_CODE Like '" & AmphorCode & "%' order by REF_desc"
        Else
            strSql = strSql & " order by REF_desc "
        End If

        ds = clsDB.QueryDataSet(strSql, "reference_code_table")

        AddItem = New ListItem(Resources.resClsMasterDropdown.Select_Tambol, 0)

        With ddlData
            .DataSource = ds.Tables("reference_code_table")
            .DataTextField = "ref_desc"
            .DataValueField = "ref_code"
        End With
        ddlData.DataBind()
        ddlData.Items.Insert(0, AddItem)

        If Not (selectData = "") Then
            ddlData.SelectedValue = selectData
        End If



        ds = Nothing


    End Sub

#End Region


#End Region

End Class
